<?php
namespace Admin\Model;
use \Frame\Libs\BaseModel;
include "./Common/CheckAdmin.php";
final class UserModel extends BaseModel{
	
	//分页获取记录
	public function fetchByPages($startrows,$pagesize){
		$sql = "SELECT * FROM love_user LIMIT $startrows,$pagesize";
		return $this->pdo->fetchAll($sql);
	}
	
	//获取具体某条记录
	public function fetchOne($uid){
		$sql = "SELECT * FROM love_user WHERE uid='$uid'";
		return $this->pdo->fetchOne($sql);
	}
	
	//获取记录数
	public function rowCount(){
		$sql = "SELECT * FROM love_user";
		return $this->pdo->rowCount($sql);
	}
	
	//编辑用户信息
	public function editUser($uid,$acc,$name,$sex,$phone,$qq,$email){
		$sql = "UPDATE love_user SET account='$acc',name='$name',email='$email',phone='$phone',sex='$sex',qq='$qq' WHERE uid='$uid'";
		return $this->pdo->exec($sql);
		//return $sql;
	}
	
	//删除
	public function delUser($id){
		$sql = "DELETE FROM love_user WHERE uid='$id'";
		return $this->pdo->exec($sql);
	}
	
	//判断是否存在
	public function isExist($acc){
		$sql = "SELECT * FROM love_user WHERE account='$acc'";
		return $this->pdo->rowCount($sql);
	}
	
	//新增
	public function addUser($account,$password,$name,$sex,$phone,$qq,$email){
	    $sql = "INSERT INTO love_user (account,password,name,email,phone,sex,qq,reg_time) VALUES ('$account','$password','$name','$email','$phone','$sex','$qq',now())";
		return $this->pdo->exec($sql);
	}
	
	//通过用户UID查询
	public function searchUserByUid($key){
		$sql = "SELECT * FROM love_user WHERE uid='$key'";
		return $this->pdo->fetchAll($sql);
	}
	
	//通过用户名（账号）查询
	public function searchUserByAccount($key){
		$sql = "SELECT * FROM love_user WHERE account LIKE '%$key%'";
		return $this->pdo->fetchAll($sql);
	}
	
	//通过手机号查询
	public function searchUserByPhone($key){
		$sql = "SELECT * FROM love_user WHERE phone LIKE '%$key%'";
		return $this->pdo->fetchAll($sql);
	}
	
	//通过邮箱查询
	public function searchUserByEmail($key){
		$sql = "SELECT * FROM love_user WHERE email LIKE '%$key%'";
		return $this->pdo->fetchAll($sql);
	}
}
?>